#include "cust_acc_open_dialog.h"
#include "ui_acc_open_dialog.h"
#include "QSqlDatabase"
#include "QDebug"
#include "QSqlQuery"
#include "QVariant"
#include "QComboBox"
#include "deposit_info.h"

acc_open_dialog::acc_open_dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::acc_open_dialog)
{
    ui->setupUi(this);
    this->setWindowTitle("申请开户");
    unit_combobox();
}

void acc_open_dialog::unit_combobox()
{
    QSqlDatabase sqlite = QSqlDatabase::database("MY");
    QSqlQuery query(sqlite);
    QString sql("SELECT employeeid FROM CLERK");
    if(!query.exec(sql))
    {
        return;
    }
    else
    {
        while(query.next())
        {
            qDebug() << query.value(0);
            ui->comboBox->addItem(query.value(0).toString());
        }
    }
    return;
}

acc_open_dialog::~acc_open_dialog()
{
    delete ui;
}

void acc_open_dialog::on_admit_clicked()
{
    deposit_info dep;
    QSqlDatabase sqlite = QSqlDatabase::database("MY");
    QSqlQuery query(sqlite);
    query.prepare("SELECT username,password,telNumber FROM CUSTOMER WHERE telNumber = ?");
    query.addBindValue(telNumberNow);
    if(!query.exec())
    {
        return;
    }
    else
    {
        while(query.next())
        {
            dep.setCustName(query.value(0).toString());
            dep.setCustPassword(query.value(1).toString());
            dep.setCustTelnumber(query.value(2).toString());
        }
    }
    dep.setCustAddress(ui->user_address->text());
    dep.setSavingsType("未进行储蓄");
    dep.setSavingsAmount("未进行储蓄");
    dep.setSavingsTime("未进行储蓄");
    dep.setIsLost("未挂失");
    dep.setLostTime("未挂失");
    dep.setClerkEmployeeid(ui->comboBox->currentText());
    query.prepare("SELECT username FROM CLERK WHERE employeeid = ?");
    query.addBindValue(ui->comboBox->currentText());
    if(!query.exec())
    {
        return;
    }
    else
    {
        while(query.next())
        {
            dep.setClerkName(query.value(0).toString());
        }
    }
    dep.setReviewStatus("待审核");
    dep.insertToDB();

}
